package com.ajie.bluetoothcard.ui;

import java.io.File;


import android.app.Application;
import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Environment;


public class CardApplication extends Application {
	private static String rootDir;
//	private static String avatarDir;
//	private static String vedioDir;
	
	private static Context mAppContext;
	
	private static int versionCode = 0;
	private static String versionName ="";
	@Override
	public void onCreate() {
		super.onCreate();
		mAppContext = this.getApplicationContext();
		
		try {
			versionCode = mAppContext.getPackageManager().getPackageInfo("com.ichano.snapecg.doctor", 0).versionCode;
			versionName = mAppContext.getPackageManager().getPackageInfo("com.ichano.snapecg.doctor", 0).versionName;
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}
		
		
		init();
	}
	
	public static Context getEcgContext(){
		return mAppContext;
	}
	
	
	public static int getVersionCode(){
		return versionCode;
	}
	public static String getVersionName(){
		return versionName;
	}
	
	public static String getVersion(){
		return versionName+"("+versionCode+")";
	}
	
	
	private void init() {
		if(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){
			rootDir = Environment.getExternalStorageDirectory().getAbsolutePath();
		}else{
			File internalCacheDir = getCacheDir();
	        rootDir = internalCacheDir.getAbsolutePath();
		}
		rootDir = rootDir+ "/bluetoothCard";
//		avatarDir = rootDir+"avatar";
//		vedioDir = rootDir+"vedio";
		createFileDir(rootDir);
//		createFileDir(avatarDir);
//		createFileDir(vedioDir);
	}
	
	public static void createFileDir(String dir){
		File file = new File(dir);
		if(!file.exists()){
			file.mkdirs();
		}
	}
	public static String getRootDir(){
		return rootDir;
	}
	
//	public static String getImageRootDir(){
//		return avatarDir;
//	}
//	
//	public static String getAudioRootDir(){
//		return vedioDir;
//	}
}
